package com.wwc.sc.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author WWC
 */
@RestController
@Slf4j
@RequestMapping(value = "/consumer/payment")
public class OrderController {

    /**
     * 集群版是根据服务名来调用服务提供者的，必须提供负载均衡算法，否则不知道该调那个服务
     */
    public static final String INVOKE_URL = "http://spring-cloud-provider-consul-payment";

    @Resource
    private RestTemplate restTemplate;

    @RequestMapping(value = "/consul")
    public String paymentInfo() {
        String result = restTemplate.getForObject(INVOKE_URL+"/payment/consul", String.class);
        log.info("消费者调用支付服务(consul)--->result:" + result);
        return result;
    }
}
